package com.amat0urheu.dao;


import com.amat0urheu.pojo.Case;
import com.amat0urheu.pojo.CaseType;
import com.amat0urheu.pojo.CloudPojo.OpenStack;
import com.amat0urheu.pojo.Experiment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CaseMapper {
    @Select("select * from mc_case_type")
    List<CaseType> getAllCaseTypes();
    @Update("update mc_case_type set caseType=#{caseType.caseType} where id=#{caseType.id} ")
    int updateCaseType(@Param("caseType") CaseType caseType);

    @Insert("insert into mc_case_type (caseType)values(#{caseType.caseType})")
    int saveCaseType(@Param("caseType") CaseType caseType);
    @Delete("delete from mc_case_type where id =#{id}")
    int removeCaseType(Integer id);
    @Select("select id,caseName,caseBackground,casePicture from mc_case ORDER BY createTime DESC")
    List<Case> getAllCases();
    @Delete("delete from mc_case where id =#{id}")
    int removeCase(Integer id);
    @Insert("insert into mc_case (caseName, caseBackground, caseContent, caseTarget, ideaPolitics, caseThought,casePicture,createTime) values (#{acase.caseName}, #{acase.caseBackground}, #{acase.caseContent}, #{acase.caseTarget}, #{acase.ideaPolitics}, #{acase.caseThought},#{acase.casePicture},CURRENT_TIMESTAMP)")
    @Options(useGeneratedKeys = true, keyProperty = "acase.id", keyColumn = "id")
    int saveCase(@Param("acase") Case acase);
    @Insert("insert into mc_case_casetype (caseId,caseTypeid) values (#{id},#{caseTypeid})")
    int saveCaseAndType(Integer id, Integer caseTypeid);
    @Select("select * from mc_case where id=#{id}")
    Case getCaseById(Integer id);
    @Select("SELECT caseTypeid FROM mc_case_casetype WHERE caseid = #{id}")
    List<Integer> getCaseTypeIdsOfCase(Integer id);
    @Select("SELECT caseTypeid FROM mc_case_casetype WHERE caseid = #{id}")
   Integer[] getCaseTypeIdsOfCase2(Integer id);
    @Update("update mc_case set caseName=#{acase.caseName},caseBackground=#{acase.caseBackground}, caseContent=#{acase.caseContent},caseTarget=#{acase.caseTarget},ideaPolitics=#{acase.ideaPolitics},caseThought=#{acase.caseThought} ,casePicture=#{acase.casePicture}where id=#{acase.id}")
    int updateCase(@Param("acase") Case acase);
    @Delete("delete from mc_case_casetype where caseid=#{id}")
    void removeCaseTypeIdofCase(Integer id);

    @Select("select * from mc_case_type  where  ${key} like #{value}")
    List<CaseType> searchCaseType(String key, String value);
    @Select("select * from mc_case  where  ${key} like #{value}")
    List<Case> searchCases(String key, String value);

    @Select("select a.id,caseName,caseBackground,casePicture from mc_case a,mc_case_casetype b where a.id=b.caseId and b.caseTypeid=#{type} ORDER BY createTime DESC")
    List<Case> getAllCasesByType(Integer type);
    @Select("select casePicture from mc_case  where  id like #{id}")
    String getOldPath(Integer id);
    @Update("update mc_case set caseName=#{acase.caseName},caseBackground=#{acase.caseBackground}, caseContent=#{acase.caseContent},caseTarget=#{acase.caseTarget},ideaPolitics=#{acase.ideaPolitics},caseThought=#{acase.caseThought} where id=#{acase.id}")
    int updateCaseNoImage(@Param("acase")Case aCase);
}
